package com.tavenli.repository;

import java.util.List;
import javax.persistence.TypedQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.tavenli.entity.PersonTempleteEntity;

@Repository
public class PersonTempleteDao extends BaseDao{
	private static Logger logger = LoggerFactory.getLogger(UserDao.class);
	public PersonTempleteEntity getPersonTempleteById(int id) {
		try {
			return this.getById(PersonTempleteEntity.class, id);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return null;
		}
	}
	/**
	 * 通过用户ID获取指纹信息
	 * @param personId
	 * @return
	 */
	public List<PersonTempleteEntity> getPersonTempleteByPersonId(int personId) {
		try {
			String hql = "from PersonTempleteEntity where personPin=?";
			TypedQuery<PersonTempleteEntity> query = this.getEntityManager().createQuery(hql, PersonTempleteEntity.class);
			query.setParameter(1, personId);
			return query.getResultList();
		} catch (Exception e) {
			logger.error(e.getMessage());
			return null;
		}
	}
	public PersonTempleteEntity getByPersonIdAndFid(
			PersonTempleteEntity personTempleteEntity) {
		try {
			String hql = "from PersonTempleteEntity where personId=? and FID=? ";
			TypedQuery<PersonTempleteEntity> query = this.getEntityManager().createQuery(hql, PersonTempleteEntity.class);
			query.setParameter(1, personTempleteEntity.getPersonId());
			query.setParameter(2, personTempleteEntity.getFID());
			if(query.getResultList().size()==0 ){
	            return null;
	        }else{
	        	return query.getSingleResult();
	        }
		} catch (Exception e) {
			logger.error(e.getMessage());
			return null;
		}
	}
	
	
	
	
}
